#!/bin/sh
#FILE: /etc/init.d/eee-overclock.sh
# change FSB clock of the Asus EEE using the 'eee' module
# setup the processor to run at 675Mhz in normal load and 900Mhz in heavy load
# using p4-clockmod and cpufreq-ondemand (overclocking in steps to prevent freezes)

. /usr/share/acpi-support/key-constants

# this script needs to be called at start time and when suspending
case "$1" in
  start)
     acpi_fakekey $KEY_PROG3
     # start overclocker module, overclock in too steps
     modprobe eee
     echo 85 24 1 > /proc/eee/fsb
     sleep 1
     echo 100 24 1 > /proc/eee/fsb
     # start frequency scaling modules
     modprobe p4-clockmod
     modprobe cpufreq-ondemand
     echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
     # set frequency to minimize fan rotation if no cpu is needed
     echo 675000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
     ;;
  stop)
     acpi_fakekey $KEY_PROG4
     # gradually restore frequency
     echo 85 24 1 > /proc/eee/fsb
     sleep 1
     echo 70 24 1 > /proc/eee/fsb
     # remove frequency management modules
     modprobe -r eee
     echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
     modprobe -r p4-clockmod
     ;;
  toggle)
    if [ -r /proc/eee/fsb ] && [ `cat /proc/eee/fsb | cut -f 1 -d " "` -gt 70 ]
	then
		exec $0 stop
	else
		exec $0 start
	fi
    ;;
  *)
    echo "USAGE: $0 (start|stop|toggle)"
  ;;
esac
